package botlab.gui.levelchooser;

import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Quentin
 */
public class JSlideShowLabel extends JLabel
{

    private ArrayList<ImageIcon> images;
    private ArrayList<String> names;
    private int index;

    public JSlideShowLabel()
    {
        images = new ArrayList<ImageIcon>();
        names = new ArrayList<String>();
        index = 0;
        this.setText(null);
        this.setHorizontalAlignment(CENTER);
    }
    
    public void reset()
    {
        if(images!=null && images.size()>0)
        {
            this.setText(null);
            index = 0;
            this.setIcon(images.get(index));
        }
    }

    public void addImage(String name)
    {
        // We resize the image before adding it
        images.add(new ImageIcon(
                new ImageIcon(JSlideShowLabel.class.getResource(name)).getImage().getScaledInstance(
                640, 480, java.awt.Image.SCALE_SMOOTH)));
        names.add(name);
        if (this.getIcon() == null)
        {
            this.setIcon(images.get(0));
        }
    }

    public void next()
    {
        this.setIcon(images.get(++index % images.size()));
    }

    public void previous()
    {
        this.setIcon(images.get(index==0?index=images.size()-1:--index % images.size()));
    }

    public int getIndex()
    {
        return index%images.size();
    }
    
    public String getImageName()
    {
        return names.get(getIndex());
    }

}
